package com.autonavi.yunda.yunji.core.engine.script;

import com.autonavi.yunda.yunji.core.enums.FunctionType;
import lombok.Getter;
import lombok.Setter;

import java.sql.Timestamp;
import java.util.Map;

public class GroovyFunctionScriptClass extends BaseGroovyScriptClass implements IFunctionScript {
    @Getter
    private String functionName;
    @Getter
    @Setter
    private Timestamp updateTime;

    public GroovyFunctionScriptClass(String script, String functionName) {
        super(script);
        this.functionName = functionName;
    }

    @Override
    public Object exeFun(Map<String, Object> params, String methodName, Object... args) {
        Object o = super.newInstance();
        // 给属性赋值
        injectParams(o, params);
        // 执行指定的方法
        return invoke(o, methodName, args);
    }

    public Object exeFun(Object instance, Map<String, Object> params, String methodName, Object... args) {
        injectParams(instance, params);
        return invoke(instance, methodName, args);
    }

    @Override
    public String getScript() {
        return script;
    }

    @Override
    public FunctionType getFunctionType() {
        return FunctionType.groovy;
    }

}
